home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 22
/
freelog 22.iso
/
Prog
/
Djgpp
/
GPC2952B.ZIP
/
info
/
gpc.i15
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
GNU Info File
|
2001-02-09
|
50.0 KB
|
3,009 lines
This is gpc.info, produced by makeinfo version 4.0 from gpc.texi.
INFO-DIR-SECTION GNU programming tools
START-INFO-DIR-ENTRY
* GPC: (gpc). The GNU Pascal Compiler.
END-INFO-DIR-ENTRY
INFO-DIR-SECTION Individual utilities
START-INFO-DIR-ENTRY
* GPC: (gpc)Invoking GPC. The GNU Pascal Compiler.
END-INFO-DIR-ENTRY
This file documents the GNU Pascal Compiler.
Copyright (C) 1988, 1996-2001 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the sections entitled "GNU General Public License", "The GNU
Project", "The GNU Manifesto" and "Funding for Free Software" are
included exactly as in the original, and provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the sections entitled "GNU General Public
License", "The GNU Project", "The GNU Manifesto" and "Funding for Free
Software" and this permission notice, may be included in translations
approved by the Free Software Foundation instead of in the original
English.
File: gpc.info, Node: Move, Next: MoveLeft, Prev: module, Up: Reference
Move
====
(Under construction.)
Synopsis
--------
procedure Move (const Source; var Dest; Count: Integer);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: MoveLeft, Next: MoveRight, Prev: Move, Up: Reference
MoveLeft
========
(Under construction.)
Synopsis
--------
procedure MoveLeft (const Source; var Dest; Count: Integer);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: MoveRight, Next: Name, Prev: MoveLeft, Up: Reference
MoveRight
=========
(Under construction.)
Synopsis
--------
procedure MoveRight (const Source; var Dest; count: Integer);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Name, Next: NE, Prev: MoveRight, Up: Reference
Name
====
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: NE, Next: near, Prev: Name, Up: Reference
NE
==
(Under construction.)
Synopsis
--------
function NE (S1, S2: String): Boolean;
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: near, Next: New, Prev: NE, Up: Reference
near
====
Synopsis
--------
Description
-----------
The `near' directive can be appended to a procedure or function
heading but is ignored by GPC. It is there for Borland compatibility,
only. (Since the GNU compilers provide a flat memory model, the
distinction between `near' and `near' pointers is void.)
Conforming to
-------------
`near' is a Borland Pascal extension.
Example
-------
program NearDemo;
var
p: procedure;
{$W-} { Don't warn about the uselessness of `near' }
procedure Foo; near; { `near' has no effect in GPC }
begin
WriteLn ('Foo')
end;
begin
p := Foo; { Works, despite the `near'. }
p
end.
See also
--------
*Note far::.
File: gpc.info, Node: New, Next: NewCString, Prev: near, Up: Reference
New
===
(Under construction.)
Synopsis
--------
procedure New (var P: ANY POINTER);
or
procedure New (var P: POINTER TO A VARIANT RECORD; TAG FIELDS);
or
procedure New (var P: POINTER TO A SCHEMA; DISCRIMINANTS);
or
procedure New (var P: POINTER TO AN OBJECT; CONSTRUCTOR CALL);
or
function New (ANY POINTER TYPE): SAME TYPE;
or
function New (VARIANT RECORD POINTER TYPE;
TAG FIELDS): SAME TYPE;
or
function New (SCHEMA POINTER TYPE;
DISCRIMINANTS): SAME TYPE;
or
function New (OBJECT POINTER TYPE;
CONSTRUCTOR CALL): SAME TYPE;
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: NewCString, Next: nil, Prev: New, Up: Reference
NewCString
==========
(Under construction.)
Synopsis
--------
function NewCString (const S: String): CString;
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: nil, Next: not, Prev: NewCString, Up: Reference
nil
===
Synopsis
--------
`nil' is a predefined constant
Description
-----------
`nil' is a predefined pointer constant that indicates an unassigned
pointer. "nil" stands for "not in list". _Every_ pointer type can be
associated with this constant.
Conforming to
-------------
`nil' is defined in ISO-7185 Standard Pascal and supported by all
known Pascal variants.
Example
-------
program NilDemo;
const
NodeNum = 10;
type
PNode = ^TNode;
TNode = record
Key: Integer;
Next: PNode
end;
var
Root, Node: PNode;
Foo: Integer;
begin
New (Root);
Root^.Key := 1; { Set root key }
Node := Root;
for Foo := 2 to NodeNum do { Create linked list with NODE_NUM nodes }
begin
New (Node^.Next);
Node := Node^.Next;
Node^.Key := Foo { Set key }
end;
Node^.Next := nil; { Mark end of linked list }
{ Shorten list by removing its first element until list is empty }
while Root <> nil do
begin
Node := Root;
WriteLn ('Current key:', Root^.Key);
Root := Root^.Next;
Dispose (Node);
Node := nil { Indicate old node is not assigned }
end
end.
See also
--------
*Note Assigned::, *Note Pointer::
File: gpc.info, Node: not, Next: Null, Prev: nil, Up: Reference
not
===
(Under construction.)
Synopsis
--------
operator not (b1, b2: Boolean) = Result: Boolean;
or
operator not (i1, i2: INTEGER TYPE) = Result: INTEGER TYPE;
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Null, Next: object, Prev: not, Up: Reference
Null
====
Synopsis
--------
var
Null: Void absolute 0;
Description
-----------
`Null' is a predefined variable at address `nil'. `Null' can be
passed as a "void" argument to a procedure, function or operator
expecting a "var" parameter. _Note_: Make sure they can handle this
case, otherwise this is likely to cause an exception and the program
will be terminated. Since `Null' is an L-value, it can be taken as
"nil-reference".
Conforming to
-------------
`Null' is a Borland Delphi extension.
Example
-------
program NullDemo;
type
PString = ^String;
var
Com1: String (25) = 'This is an amazing number';
Com2: String (25) = 'This is a boring number';
procedure FooBar (Foo: Integer; var Comment: PString);
begin
if Odd (Foo) then
WriteLn ('FooBar:', Foo, ' is odd')
else
WriteLn ('FooBar:', Foo, ' is even');
if @Comment <> nil then
if not Odd(foo) then
Comment := @Com1
else
Comment := @Com2
end;
var
S: String (25);
P: PString value @S;
begin
{ FooBar allows you to leave out variables
for any information you might not need }
FooBar (1, Null);
{ But FooBar is flexible, after all }
FooBar (6, p);
WriteLn ('FooBar said about 6: `', P^, '''')
end.
See also
--------
*Note nil::
File: gpc.info, Node: object, Next: Odd, Prev: Null, Up: Reference
object
======
Synopsis
--------
Description
-----------
The keyword `object' is used to declare a new object type:
type
foo = object
a: Integer;
constructor Init;
procedure Bar (x: Integer); virtual;
end;
(For a longer example, see *Note OOP::.)
Conforming to
-------------
GNU Pascal follows the Borland Pascal 7.0 object model.
ISO Pascal does not support Object-orientated programming. There is
an ANSI draft for an "Object Pascal" language which is not yet
supported by GPC, but planned. The Delphi language, also called "Object
Pascal" by Borland, is currently not supported by GPC either.
Example
-------
See also
--------
*Note OOP::, *Note record::.
File: gpc.info, Node: Odd, Next: of, Prev: object, Up: Reference
Odd
===
Synopsis
--------
function Odd (i: Integer): Boolean;
Description
-----------
`Odd' checks the parity of its argument `i'. It returns `True' if
the argument is odd, `False' if it is even.
Conforming to
-------------
`Odd' is defined in ISO-7185 Standard Pascal and supported by all
known Pascal variants.
Example
-------
program OddDemo;
var
Foo: Integer;
begin
Write ('Please enter an odd number: ');
ReadLn (Foo);
if not Odd (Foo) then
WriteLn ('Odd''s not even! Something''s odd out there ...')
else
WriteLn (Foo, ' is pretty odd.')
end.
See also
--------
File: gpc.info, Node: of, Next: only, Prev: Odd, Up: Reference
of
==
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: only, Next: operator, Prev: of, Up: Reference
only
====
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: operator, Next: or, Prev: only, Up: Reference
operator
========
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: or, Next: or else, Prev: operator, Up: Reference
or
==
Synopsis
--------
operator or (operand1, operand2: Boolean) = Result: Boolean;
or
operator or (operand1, operand2: INTEGER TYPE) = Result: INTEGER TYPE;
or
procedure or (var operand1: INTEGER TYPE; operand2: INTEGER TYPE);
Description
-----------
In GNU Pascal, `or' has three built-in meanings:
1. Logical "or" between two `Boolean'-type expressions. The result
of the operation is of `Boolean' type.
By default, `or' acts as a short-circuit operator in GPC: If the
first operand is `True', the second operand is not evaluated
because the result is already known to be `True'. You can change
this to complete evaluation using the `--no-short-circuit'
command-line option or the `{$B+}' compiler directive.
2. Bitwise "or" between two integer-type expressions. The result is
of the common integer type of both expressions.
3. Use as a "procedure": `operand1' is "or"ed bitwise with
`operand2'; the result is stored in `operand1'.
Conforming to
-------------
The logical `or' operator is defined in ISO-7185 Standard Pascal.
According to ISO, you cannot rely on `or' being a short-circuit
operator. On the other hand, GPC's default behaviour does _not_
contradict the ISO standard. (See *Note or_else::.) However, since it
seems to be a de-facto standard among ISO Pascal compilers to evaluate
both operands of `or', GPC switches to `--no-short-circuit' mode if one
of the language dialect options selecting ISO Pascal, for instance
`--extended-pascal', is given. Use `--short-circuit' to override.
Use of `or' as a bitwise operator for integers is a Borland Pascal
extension.
Use of `or' as a "procedure" is a GNU Pascal extension.
Example
-------
program OrDemo;
var
a, b, c: Integer;
begin
if (a = 0) or (b = 0) then { logical `or' }
c := 1
else if a or b = 0 then { bitwise `or' }
c := 2
else
or (c, a) { same as `c := c or a' }
end.
Note the difference between the logical `or' and the bitwise `or':
When `a' is 2 and `b' is 4, then `a or b' is 6. *Beware:* `a or b = 0'
happens to mean the same as `(a = 0) and (b = 0)'. (Note the `and'!)
Since bitwise `or' has a higher priority than the `=' operator,
parentheses are needed in `if (a = 0) or (b = 0)' because otherwise `0
or b' would be calculated first, and the remainder would cause a parse
error.
See also
--------
*Note and::, *Note xor::, *Note Operators::.
File: gpc.info, Node: or else, Next: Ord, Prev: or, Up: Reference
or else
=======
Synopsis
--------
{ `or else' is built in. A user-defined operator cannot consist of
two words. }
operator or else (operand1, operand2: Boolean) = Result: Boolean;
Description
-----------
`or else' is an alias for the short-circuit logical operator
`or_else'.
Conforming to
-------------
While `or_else' is defined in ISO-10206 Extended Pascal, `or else'
is a GNU Extension.
Example
-------
program OrElseDemo;
var
a: Integer;
begin
ReadLn (a);
if (a = 0) or else (100 div a > 42) then { This is safe. }
WriteLn ('100 div a > 42')
end.
See also
--------
*Note or_else::, *Note or::, *Note and then::.
File: gpc.info, Node: Ord, Next: or_else, Prev: or else, Up: Reference
Ord
===
(Under construction.)
Synopsis
--------
function Ord (Ch: Char): Integer;
Description
-----------
Conforming to
-------------
`Ord' is defined in ISO-7185 Standard Pascal and supported by all
known Pascal variants.
Example
-------
See also
--------
File: gpc.info, Node: or_else, Next: otherwise, Prev: Ord, Up: Reference
or_else
=======
Synopsis
--------
operator or_else (operand1, operand2: Boolean) = Result: Boolean;
Description
-----------
The `or_else' short-circuit logical operator performs the same
operation as the logical operator `or'. But while the ISO standard does
not specify anything about the evaluation of the operands of `or' -
they may be evaluated in any order, or not at all - `or_else' has a
well-defined behaviour: It evaluates the first operand. If the result
is `True', `or_else' returns `True' without evaluating the second
operand. If it is `False', the second operand is evaluated and returned.
GPC by default treats `or' and `or_else' exactly the same. If you
want, for some reason, to have both operands of `or' evaluated
completely, you must assign both to temporary variables and then use
`or' - or `or_else', it does not matter.
Conforming to
-------------
`or_else' is an ISO-10206 Extended Pascal extension.
Some people think that the ISO standard requires both operands of
`or' to be evaluated. This is false. What the ISO standard _does_ say
is that you cannot rely on a certain order of evaluation of the
operands of `or'; in particular things like the following program can
crash according to ISO Pascal, although they cannot crash when compiled
with GNU Pascal running in default mode.
program OrBug;
var
a: Integer;
begin
ReadLn (a);
if (a = 0) or (100 div a > 42) then { This is NOT safe! }
WriteLn ('You''re lucky. But the test could have crashed...')
end.
Example
-------
program Or_ElseDemo;
var
a: Integer;
begin
ReadLn (a);
if (a = 0) or_else (100 div a > 42) then { This is safe. }
WriteLn ('100 div a > 42')
end.
See also
--------
*Note or else::, *Note or::, *Note and_then::.
File: gpc.info, Node: otherwise, Next: Output, Prev: or_else, Up: Reference
otherwise
=========
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Output, Next: Override, Prev: otherwise, Up: Reference
Output
======
(Under construction.)
Synopsis
--------
var
Output: Text;
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Override, Next: Pack, Prev: Output, Up: Reference
Override
========
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Pack, Next: packed, Prev: Override, Up: Reference
Pack
====
(Under construction.)
Synopsis
--------
Description
-----------
procedure Pack (Source: UNPACKED ARRAY;
FirstElement: INDEX TYPE;
var Dest: PACKED ARRAY);
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: packed, Next: Page, Prev: Pack, Up: Reference
packed
======
Synopsis
--------
Description
-----------
`packed' is a reserved word. According to ISO-7185 Standard Pascal
it can precede `array' and `record' type definitions to indicate that
memory usage should be minimized for variables of this type, possibly
at the expense of loss of speed.
As a GNU extension, `packed' can also be applied to *Note Subrange
Types::.
Conforming to
-------------
The reserved word `packed' is defined in ISO-7185 Standard Pascal.
According to ISO standard, only _packed_ arrays of char with lower
bound 1 qualify as strings of fixed length. GNU Pascal neither requires
`packed' nor the lower bound of 1 here.
Example
-------
program PackedDemo;
type
MonthInt = packed 1 .. 12; { needs one byte }
FastMonthInt = 1 .. 12; { needs four bytes }
FixString10 = packed array [1 .. 10] of Char;
FoxyString10 = array [0 .. 9] of Char;
Flags = packed array [1 .. 32] of Boolean; { needs four Bytes }
DateRec = packed record
Day: 1 .. 31; { five bits }
Month: MonthInt; { four bits }
Year: Integer (15) { 15 bits = -16384 .. 16383 }
end;
Dates = array [1 .. 1000] of DateRec;
var
S: FixString10;
T: FoxyString10;
begin
S := 'Hello!'; { blank padded }
WriteLn (S);
T := 'GNU Pascal'; { GPC extension: this also works. }
WriteLn (T)
end.
`DateRec' has 24 bits = 3 bytes in total; `Dates' has 3000 bytes.
See also
--------
*Note Pack::, *Note Unpack::, *Note SizeOf::, *Note AlignOf::, *Note
BitSizeOf::.
File: gpc.info, Node: Page, Next: PAnsiChar, Prev: packed, Up: Reference
Page
====
(Under construction.)
Synopsis
--------
procedure Page (var F: Text);
or
procedure Page;
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: PAnsiChar, Next: ParamCount, Prev: Page, Up: Reference
PAnsiChar
=========
(Under construction.)
Synopsis
--------
type
PAnsiChar = ^AnsiChar;
Description
-----------
Conforming to
-------------
Example
-------
program PAnsiCharDemo;
var
s: PAnsiChar;
begin
s := 'Hello, world!';
{$X+}
WriteLn (s)
end.
See also
--------
File: gpc.info, Node: ParamCount, Next: ParamStr, Prev: PAnsiChar, Up: Reference
ParamCount
==========
Synopsis
--------
function ParamCount: Integer;
Description
-----------
`ParamCount' returns the number of command-line arguments given to
the program. `ParamCount' returns 0 if no arguments have been given to
the program; the name of the program as an implicit argument is not
counted.
Conforming to
-------------
`ParamCount' is a Borland Pascal extension.
Example
-------
program ParamCountDemo;
var
i: Integer;
begin
WriteLn ('You have invoked this program with ',
ParamCount, ' arguments.');
WriteLn ('These are:');
for i := 1 to ParamCount do
WriteLn (ParamStr (i))
end.
See also
--------
*Note ParamStr::.
File: gpc.info, Node: ParamStr, Next: PChar, Prev: ParamCount, Up: Reference
ParamStr
========
(Under construction.)
Synopsis
--------
function ParamStr (ParmNumber: Integer): String;
Description
-----------
*Note:* If you are using the Dos (DJGPP) or MS-Windows (mingw32)
version of GPC and are getting unexpected results from `ParamStr',
please see the section "Command-line Arguments Handling in DJGPP" of
the DJGPP FAQ list.
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: PChar, Next: Pi, Prev: ParamStr, Up: Reference
PChar
=====
(Under construction.)
Synopsis
--------
type
PChar = ^Char;
or
type
PChar = CString;
Description
-----------
Conforming to
-------------
Example
-------
program PCharDemo;
var
s: PChar;
begin
s := 'Hello, world!';
{$X+}
WriteLn (s)
end.
See also
--------
File: gpc.info, Node: Pi, Next: Pointer, Prev: PChar, Up: Reference
Pi
==
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Pointer, Next: Polar, Prev: Pi, Up: Reference
Pointer
=======
(Under construction.)
Synopsis
--------
type
Pointer { built-in type }
Description
-----------
Conforming to
-------------
Example
-------
program PointerDemo;
var
a: Integer;
b: Boolean;
p: Pointer;
begin
p := nil;
p := @a;
p := @b
end.
See also
--------
File: gpc.info, Node: Polar, Next: Pos, Prev: Pointer, Up: Reference
Polar
=====
(Under construction.)
Synopsis
--------
function Polar (rho, phi: Real): Complex;
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Pos, Next: Position, Prev: Polar, Up: Reference
Pos
===
(Under construction.)
Synopsis
--------
function Pos (SearchPattern, Source: String): Integer;
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Position, Next: pow, Prev: Pos, Up: Reference
Position
========
(Under construction.)
Synopsis
--------
function Position (var F: TYPED FILE);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: pow, Next: Pred, Prev: Position, Up: Reference
pow
===
(Under construction.)
Synopsis
--------
operator pow (base: Real; exponent: Integer) = power: Real;
or
operator pow (base: Complex; exponent: Integer) = power: Complex;
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Pred, Next: private, Prev: pow, Up: Reference
Pred
====
Synopsis
--------
function Pred (i: ORDINAL TYPE): ORDINAL TYPE;
or
function Pred (i: ORDINAL TYPE; j: Integer): ORDINAL TYPE;
or, with extended syntax (`--extended-syntax' or `{$X+}'),
function Pred (p: POINTER TYPE): POINTER TYPE;
or
function Pred (p: POINTER TYPE; j: Integer): POINTER TYPE;
Description
-----------
Returns the predecessor of the ORDINAL TYPE value `i', or, if the
second argument `j' is given, its `j'th predecessor. For integer
values `i', this is `i - 1' (or `i - j'). (No, `Pred' does _not_ work
faster than plain subtraction. Both are optimized to a single machine
instruction or even expanded by the compiler, if possible.)
If extended syntax is on, the argument may also be a pointer value.
In this case, the address is decremented by the size of the variable
pointed to, or, if `j' is given, by `j' times the size of the variable
pointed to. If `p' points to an element of an array, the returned
pointer will point to the (`j'th) previous element of the array.
Conforming to
-------------
The `Pred' function is defined in ISO-7185 Standard Pascal. The
optional second parameter is defined in ISO-10206 Extended Pascal.
Application of `Pred' to pointers is defined in Borland Pascal. The
combination of the second argument with application to pointers is a
GNU extension.
Example
-------
program PredDemo;
type
Metasyntactical = (foo, bar, baz);
var
m: Metasyntactical;
c: Char;
a: array [1 .. 7] of Integer;
p: ^Integer;
begin
m := Pred (bar); { foo }
c := Pred ('Z', 2); { 'X' }
a [1] := 42;
a [4] := Pred (a [1]); { 41 }
a [5] := Pred (a [4], 3); { 38 }
{$X+}
p := @a [5];
p := Pred (p); { now p points to a [4] }
p := Pred (p, 3); { now p points to a [1] }
end.
See also
--------
*Note Succ::, *Note Dec::, *Note Pointer Arithmetics::.
File: gpc.info, Node: private, Next: procedure, Prev: Pred, Up: Reference
private
=======
(Under construction.)
Synopsis
--------
Description
-----------
GPC currently accepts but ignores the `private' directive in object
type declarations.
Conforming to
-------------
Example
-------
See also
--------
*Note protected::, *Note public::, *Note published::.
File: gpc.info, Node: procedure, Next: program, Prev: private, Up: Reference
procedure
=========
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: program, Next: property, Prev: procedure, Up: Reference
program
=======
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: property, Next: protected, Prev: program, Up: Reference
property
========
Not yet implemented.
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: protected, Next: PtrCard, Prev: property, Up: Reference
protected
=========
(Under construction.)
Synopsis
--------
Description
-----------
The Extended Pascal meaning of `protected' is supported by GPC.
GPC currently accepts but ignores the `protected' directive in
object type declarations.
Conforming to
-------------
Extended Pascal and Borland Pascal, but with different meanings.
Example
-------
See also
--------
*Note const::, *Note import::, *Note private::, *Note public::,
*Note published::.
File: gpc.info, Node: PtrCard, Next: PtrDiffType, Prev: protected, Up: Reference
PtrCard
=======
(Under construction.)
Synopsis
--------
type
PtrCard = Cardinal (BitSizeOf (Pointer));
Description
-----------
Conforming to
-------------
Example
-------
program PtrCardDemo;
var
a: PtrCard;
p: Pointer;
begin
New (p);
a := PtrCard (p);
Inc (a);
p := Pointer (a)
end.
See also
--------
File: gpc.info, Node: PtrDiffType, Next: PtrInt, Prev: PtrCard, Up: Reference
PtrDiffType
===========
(Under construction.)
Synopsis
--------
type
PtrDiffType { built-in type }
Description
-----------
Conforming to
-------------
Example
-------
program PtrDiffTypeDemo;
var
a: array [1 .. 10] of Integer;
d: PtrDiffType;
p, q: Pointer;
begin
p := @a [1];
q := @a [4];
{$X+}
d := q - p
end.
See also
--------
File: gpc.info, Node: PtrInt, Next: PtrWord, Prev: PtrDiffType, Up: Reference
PtrInt
======
(Under construction.)
Synopsis
--------
type
PtrCard = Integer (BitSizeOf (Pointer));
Description
-----------
Conforming to
-------------
Example
-------
program PtrIntDemo;
var
a: PtrInt;
p: Pointer;
begin
New (p);
a := PtrInt (p);
Inc (a);
p := Pointer (a)
end.
See also
--------
File: gpc.info, Node: PtrWord, Next: public, Prev: PtrInt, Up: Reference
PtrWord
=======
(Under construction.)
Synopsis
--------
type
PtrWord = PtrCard;
Description
-----------
Conforming to
-------------
Example
-------
program PtrWordDemo;
var
a: PtrWord;
p: Pointer;
begin
New (p);
a := PtrWord (p);
Inc (a);
p := Pointer (a)
end.
See also
--------
File: gpc.info, Node: public, Next: published, Prev: PtrWord, Up: Reference
public
======
(Under construction.)
Synopsis
--------
Description
-----------
GPC currently accepts but ignores the `public' directive in object
type declarations.
Conforming to
-------------
Example
-------
See also
--------
*Note private::, *Note protected::, *Note published::.
File: gpc.info, Node: published, Next: Put, Prev: public, Up: Reference
published
=========
(Under construction.)
Synopsis
--------
Description
-----------
GPC currently accepts but ignores the `published' directive in
object type declarations.
Conforming to
-------------
Example
-------
See also
--------
*Note private::, *Note protected::, *Note public::.
File: gpc.info, Node: Put, Next: qualified, Prev: published, Up: Reference
Put
===
(Under construction.)
Synopsis
--------
procedure Put (var F: TYPED FILE);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: qualified, Next: Random, Prev: Put, Up: Reference
qualified
=========
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Random, Next: Randomize, Prev: qualified, Up: Reference
Random
======
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Randomize, Next: Re, Prev: Random, Up: Reference
Randomize
=========
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Re, Next: Read, Prev: Randomize, Up: Reference
Re
==
Synopsis
--------
function Re (z: Complex): Real;
Description
-----------
`Re' extracts the real part of the complex number `z'.
Conforming to
-------------
`Re' is an ISO-10206 Extended Pascal extension.
Example
-------
program ReDemo;
var
z: Complex;
begin
z := Cmplx (1, 2);
WriteLn (Re (z) : 0 : 5)
end.
See also
--------
*Note Cmplx::, *Note Im::, *Note Arg::
File: gpc.info, Node: Read, Next: ReadLn, Prev: Re, Up: Reference
Read
====
(Under construction.)
Synopsis
--------
procedure Read (var F: TYPED FILE; VARIABLE);
or
procedure Read (var F: Text; VARIABLES);
or
procedure Read (VARIABLES);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: ReadLn, Next: ReadStr, Prev: Read, Up: Reference
ReadLn
======
(Under construction.)
Synopsis
--------
procedure ReadLn (var F: Text; VARIABLES);
or
procedure ReadLn (VARIABLES);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: ReadStr, Next: Real, Prev: ReadLn, Up: Reference
ReadStr
=======
(Under construction.)
Synopsis
--------
procedure ReadStr (const S: String; VARIABLES);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Real, Next: record, Prev: ReadStr, Up: Reference
Real
====
(Under construction.)
Synopsis
--------
type
Real { built-in type }
Description
-----------
Conforming to
-------------
Example
-------
program RealDemo;
var
a: Real;
begin
a := 42;
WriteLn (a)
end.
See also
--------
File: gpc.info, Node: record, Next: register, Prev: Real, Up: Reference
record
======
Synopsis
--------
In type definitions:
RECORD TYPE IDENTIFIER = record
FIELD IDENTIFIER : TYPE DEFINITION
...
FIELD IDENTIFIER : TYPE DEFINITION
end;
or, with a variant part,
RECORD TYPE IDENTIFIER = record
FIELD IDENTIFIER : TYPE DEFINITION
...
FIELD IDENTIFIER : TYPE DEFINITION
case bar: VARIANT TYPE of
SELECTOR: (FIELD DECLARATIONS);
SELECTOR: (FIELD DECLARATIONS);
...
end;
or, without a variant selector field,
RECORD TYPE IDENTIFIER = record
FIELD IDENTIFIER : TYPE DEFINITION
...
FIELD IDENTIFIER : TYPE DEFINITION
case VARIANT TYPE of
SELECTOR: (FIELD DECLARATIONS);
SELECTOR: (FIELD DECLARATIONS);
...
end;
Description
-----------
The reserved word `record' starts the definition of a new record
type.
Records can be `packed' to save memory usage at the expense of speed.
The variants of a variant record may - but are not required to -
share one location in memory (inside the record).
Sometimes variant records are used to emulate type casting in
ISO-7185 Standard Pascal. This is in fact a violation of the standard
and not portable. There is intentionally _no_ possibility in ISO-7185
Standard Pascal to emulate type casting.
Conforming to
-------------
The reserved word `record' and record types are defined in ISO-7185
Standard Pascal.
According to ISO Pascal, the variant type must be an identifier.
GNU Pascal, like UCSD and Borland Pascal, also allows a subrange here.
Subranges in the variant fields, e.g. `case Integer of 2 .. 5', are
a GPC extension.
Example
-------
program RecordDemo;
type
FooPtr = ^Foo;
Foo = record
Bar: Integer;
NextFoo: fooPtr;
case Choice: 1 .. 3 of
1: (a: Integer); { These three choices may share }
2: (b: Real); { one location in memory. }
3: (c: Char;
d: Boolean);
end;
SmallFoo = packed record
b: 0 .. 3;
a: Integer (5);
r: Boolean
end; { needs 1 byte }
var
f: Foo;
begin
f.b := 3.14;
WriteLn (f.a) { yields some strange number which is part of the }
{ internal representation of the real number `f.b'. }
end.
See also
--------
*Note packed::, *Note case Statement::
File: gpc.info, Node: register, Next: Release, Prev: record, Up: Reference
register
========
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Release, Next: Rename, Prev: register, Up: Reference
Release
=======
(Under construction.)
Synopsis
--------
procedure Release (P: Pointer);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Rename, Next: repeat, Prev: Release, Up: Reference
Rename
======
(Under construction.)
Synopsis
--------
procedure Rename (var F: ANY FILE; NewName: String);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: repeat, Next: Reset, Prev: Rename, Up: Reference
repeat
======
Synopsis
--------
repeat
STATEMENT;
...
STATEMENT;
until BOOLEAN EXPRESSION;
Description
-----------
The `repeat ... until' statement declares a loop. For further
description see *Note repeat Statement::.
Conforming to
-------------
`repeat' is defined in ISO-7185 Standard Pascal and supported by all
known Pascal variants.
Example
-------
program RepeatDemo;
var
Number, Sum: Integer;
begin
WriteLn ('Black Jack for beginners.');
WriteLn ('You can choose your cards yourself. :-)');
Sum := 0;
repeat
Write ('Your card? ');
ReadLn (Number);
Inc (Sum, Number);
WriteLn ('You have ', Sum, '.')
until Sum >= 21;
if Sum = 21 then
WriteLn ('You win!')
else
WriteLn ('You lose.')
end.
See also
--------
*Note while Statement::, *Note for Statement::
File: gpc.info, Node: Reset, Next: resident, Prev: repeat, Up: Reference
Reset
=====
(Under construction.)
Synopsis
--------
procedure Reset (var F: ANY FILE; [FileName: String;]
[BlockSize: Cardinal]);
Description
-----------
`Reset' opens an existing file for reading. The file pointer is
positioned at the beginning of the file.
Like `Rewrite', `Append' and `Extend' do, `Reset' accepts an
optional second and third parameter for the name of the file in the
filesystem and, for untyped files, the block size of the file. (For
details, see *Note Rewrite::.)
Conforming to
-------------
`Reset' is defined in ISO-7185 Standard Pascal. The `BlockSize'
parameter is a Borland Pascal extension. The `FileName' parameter is a
GNU extension.
Example
-------
program ResetDemo;
var
Sample: Text;
s: String (42);
begin
Rewrite (Sample); { Open an internal file for writing }
WriteLn (Sample, 'Hello, World!');
Reset (Sample); { Open it again for reading }
ReadLn (Sample, s);
WriteLn (s);
Close (Sample)
end.
See also
--------
*Note Assign::, *Note Rewrite::, *Note Append::, *Note Extend::.
File: gpc.info, Node: resident, Next: restricted, Prev: Reset, Up: Reference
resident
========
Not yet implemented.
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: restricted, Next: Result, Prev: resident, Up: Reference
restricted
==========
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Result, Next: Return, Prev: restricted, Up: Reference
Result
======
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Return, Next: ReturnAddress, Prev: Result, Up: Reference
Return
======
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: ReturnAddress, Next: Rewrite, Prev: Return, Up: Reference
ReturnAddress
=============
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Rewrite, Next: RmDir, Prev: ReturnAddress, Up: Reference
Rewrite
=======
(Under construction.)
Synopsis
--------
procedure Rewrite (var F: ANY FILE; [FileName: String;]
[BlockSize: Cardinal]);
Description
-----------
`Rewrite' opens a file for writing. If the file does not exist, it
is created. The file pointer is positioned at the beginning of the file.
Like `Reset', `Append' and `Extend' do, `Rewrite' accepts an
optional second and third parameter.
The second parameter can specify the name of the file in the
filesystem. If it is omitted, the following alternative ways can be
used to specify the name. There are so many different ways in order to
be compatible to the idiosyncrasies of as many other Pascal compilers
as possible. (If you know about yet other ways, let us know...)
* The `Assign' procedure (*note Assign::)
* The `Bind' procedure (*note Bind::)
The following ways are only available if the file is external, i.e.
a global variable which is mentioned in the program header. Otherwise,
the file will be internal, i.e. get no name in the file system (it may
get a name temporarily, but will then be erased automatically again).
This is useful to store some data and read them back within a program
without the need for permanent storage.
* A command-line parameter of the form `--gpc-rts=-nF:NAME' where F
is the identifier of the file variable.
* If the file was mentioned in the program header and the option
`--transparent file names' (*note GPC Command Line Options::) was
set, the file name will be identical to the identifier converted
to lower-case.
* Otherwise, the user will be prompted for a file name.
The last optional parameter determines the block size of the file.
It is valid only for untyped files. Almost always, 1 is the most
reasonable value here. However, the existence of this parameter is a BP
compatibility feature, and in BP it defaults to 128 because of historic
misdesign. Therefore, GPC requires this parameter to be present. In
`--borland-pascal' mode, it makes it optional (like BP does), but warns
about the strange default if omitted.
Conforming to
-------------
`Rewrite' is defined in ISO-7185 Standard Pascal. The `BlockSize'
parameter is a Borland Pascal extension. The `FileName' parameter is a
GNU extension.
Example
-------
program RewriteDemo;
var
Sample: Text;
begin
Assign (Sample, 'sample.txt');
Rewrite (Sample);
WriteLn (Sample, 'Hello, World!');
Close (Sample)
end.
See also
--------
*Note Assign::, *Note Reset::, *Note Append::, *Note Extend::, *Note
Update::.
File: gpc.info, Node: RmDir, Next: Root, Prev: Rewrite, Up: Reference
RmDir
=====
Synopsis
--------
procedure RmDir (Directory: String);
Description
-----------
`RmDir' removes the given DIRECTORY if its argument is a valid
parameter to the related operating system's function. Otherwise a
runtime error is caused.
Conforming to
-------------
`RmDir' is a Borland Pascal extension.
Example
-------
program RmDirDemo;
var
Foo: String (127);
begin
WriteLn ('Enter directory name to remove: ');
ReadLn (Foo);
{$i-} { Suppress exit on error }
RmDir (Foo);
if IOResult <> 0 then
WriteLn ('Directory ', foo, ' could not be removed.')
else
WriteLn ('Okay.')
end.
See also
--------
*Note ChDir::, *Note MkDir::
File: gpc.info, Node: Root, Next: Round, Prev: RmDir, Up: Reference
Root
====
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Round, Next: RunError, Prev: Root, Up: Reference
Round
=====
Synopsis
--------
function Round (x: Real): Integer;
Description
-----------
`Round' returns the nearest integer to `x'. The result is of type
integer. In the case of equidistance, the result is machine-dependent
(or depends on the behaviour of the processor).
Conforming to
-------------
`Round' is defined in ISO-7185 Standard Pascal and supported by all
known Pascal variants.
Example
-------
program RoundDemo;
var
Foo: Real;
begin
foo := 9.876543;
WriteLn (Round (Foo)); { Prints 10 }
foo := 3.456789;
WriteLn (Round (Foo)) { Prints 3 }
end.
See also
--------
*Note Round::
File: gpc.info, Node: RunError, Next: Seek, Prev: Round, Up: Reference
RunError
========
(Under construction.)
Synopsis
--------
procedure RunError (ErrorCode: Integer);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Seek, Next: SeekRead, Prev: RunError, Up: Reference
Seek
====
(Under construction.)
Synopsis
--------
procedure Seek (var F: TYPED FILE; NewPosition: Integer);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: SeekRead, Next: SeekUpdate, Prev: Seek, Up: Reference
SeekRead
========
(Under construction.)
Synopsis
--------
procedure SeekRead (var F: TYPED FILE; NewPosition: Integer);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: SeekUpdate, Next: SeekWrite, Prev: SeekRead, Up: Reference
SeekUpdate
==========
(Under construction.)
Synopsis
--------
procedure SeekUpdate (var F: TYPED FILE; NewPosition: Integer);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: SeekWrite, Next: segment, Prev: SeekUpdate, Up: Reference
SeekWrite
=========
(Under construction.)
Synopsis
--------
procedure SeekWrite (var F: TYPED FILE; NewPosition: Integer);
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: segment, Next: Self, Prev: SeekWrite, Up: Reference
segment
=======
Not yet implemented.
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: Self, Next: set, Prev: segment, Up: Reference
Self
====
(Under construction.)
Synopsis
--------
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: set, Next: SetFileTime, Prev: Self, Up: Reference
set
===
(Under construction.)
Synopsis
--------
In type definitions:
set of TYPE { built-in type class }
Description
-----------
Conforming to
-------------
Example
-------
See also
--------
File: gpc.info, Node: SetFileTime, Next: SetLength, Prev: set, Up: Reference
SetFileTime
===========
procedure SetFileTime (var f : ANY FILE;
AccessTime, ModificationTime : UnixTimeType);
Synopsis
--------
Description
-----------
Conforming to
-------------
`SetFileTime' is a GNU extension.
Example
-------
See also
--------
File: gpc.info, Node: SetLength, Next: SetType, Prev: SetFileTime, Up: Reference
SetLength
=========
Synopsis
--------
procedure SetLength (var S: String; NewLength: Integer);
Description
-----------
`SetLength' explicitly assigns a new length `NewLength' to the
string parameter `S'. The contents of the string is _not_ changed; if
the operation increases the length of the string, the characters
appended at the end are _undefined_.
Conforming to
-------------
`SetLength' is a Borland Delphi 2.0 extension.
Example
-------
program SetLengthDemo;
var
S : String (26);
begin
S := 'Hello, world!';
SetLength (S, Length ('Hello'));
WriteLn (S); { 'Hello' }
SetLength (S, 26);
WriteLn (S); { 'Hello, world!(%$xy"!#&~+(/]' }
{ undefined characters ^^^^^^^^^^^^^^ }
SetLength (S, 42); { The overflow is *not* (yet) detected. }
WriteLn (S); { This might cause a runtime error or crash. }
end.
See also
--------
*Note Length::, *Note String::, *Note SetType::.
File: gpc.info, Node: SetType, Next: shl, Prev: SetLength, Up: Reference
SetType
=======
Synopsis
--------
procedure SetType (var SomeObject; VMT: Pointer);
Description
-----------
The procedure `SetType' explicitly assigns a value to the implicit
VMT field of an object. This is normally done implicitly when a
constructor is called.
You can use this to write a polymorphic I/O routine which reads an
object from a file. In this case, you cannot reasonably use `New' to
allocate the storage, but you `GetMem' it and initialize the object
manually using `SetType' before calling the constructor explicitly.
This is a dangerous feature which yields a warning unless `{$X+}' is
given.
Conforming to
-------------
`SetType' is a GNU extension.
Example
-------
program SetTypeDemo;
type
BasePtr = ^BaseObj;
BaseObj = object
constructor Load;
end;
ChildObj = object (BaseObj)
constructor Load;
end;
constructor BaseObj.Load;
begin
end;
constructor ChildObj.Load;
begin
end;
{$X+}
{ This is somewhat fragmentary code. }
function GetObject (var InputFile: File) = Result: BasePtr;
const
VMTTable: array [1 .. 2] of Pointer =
(TypeOf (BaseObj), TypeOf (ChildObj));
var
Size: Cardinal;
TypeID: Integer;
VMT: Pointer;
begin
{ Read the size of the object from some file and store it in `Size'. }
BlockRead (InputFile, Size, SizeOf (Size));
{ Allocate memory for the object. }
GetMem (Result, Size);
{ Read some ID from some file. }
BlockRead (InputFile, TypeID, SizeOf (TypeID));
{ Look up the `VMT' from some table. }
{ Range checking wouldn't be a bad idea here... }
VMT := VMTTable [TypeID];
SetType (Result^, VMT);
{ Now the object is ready, and the constructor can be called. }
{ Look up the correct constructor from some table and call it. }
end;
begin
end.
See also
--------
*Note TypeOf::, *Note OOP::.
File: gpc.info, Node: shl, Next: ShortBool, Prev: SetType, Up: Reference
shl
===
Synopsis
--------
operator shl (operand1, operand2: INTEGER TYPE) = Result: INTEGER TYPE;
or
procedure shl (var operand1: INTEGER TYPE; operand2: INTEGER TYPE);
Description
-----------
In GNU Pascal, `shl' has two built-in meanings:
1. Bitwise shift left of an integer-type expression by another
integer value. The result is of the type of the first operand.
2. Use as a "procedure": `operand1' is shifted left by `operand2';
the result is stored in `operand1'.
Conforming to
-------------
`shl' is a Borland Pascal extension.
Use of `shl' as a "procedure" is a GNU Pascal extension.
Example
-------
program ShlDemo;
var
a: Integer;
begin
a := 1 shl 7; { yields 128 = 2 pow 7 }
shl (a, 4) { same as `a := a shl 4' }
end.
See also
--------
*Note shr::, *Note Operators::.
File: gpc.info, Node: ShortBool, Next: ShortCard, Prev: shl, Up: Reference
ShortBool
=========
(Under construction.)
Synopsis
--------
type
ShortBool = Boolean (BitSizeOf (ShortInt));
Description
-----------
Conforming to
-------------
Example
-------
program ShortBoolDemo;
var
a: ShortBool;
begin
ShortInt (a) := 1;
if a then WriteLn ('Ord (True) = 1')
end.
See also
--------